package com.xxxx.mail;


import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

/**
 * 邮件的 redis 序列化：
 */
@Component
public class RedisConfigMail {

    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory){
        //序列化
        RedisTemplate<String,Object> template = new RedisTemplate<>();
        // String类型，序列化
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        //配置hash类型，序列化
        template.setHashKeySerializer(new StringRedisSerializer());
        template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        //加入工厂
        template.setConnectionFactory(redisConnectionFactory);
        //返回
        return template;
    }
}
